package com.sky.controller.admin;

import com.sky.dto.SetmealDTO;
import com.sky.dto.SetmealPageQueryDTO;
import com.sky.entity.Setmeal;
import com.sky.result.PageBean;
import com.sky.result.Result;
import com.sky.service.SetmealService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/setmeal")
@Api(tags = "套餐相关接口")
@Slf4j
@AllArgsConstructor//所有构造参数
public class SetmealController {
    private final SetmealService service;

    /**
     * 修改套餐
     * @param setmealDTO 条件
     * @return R
     */
    @ApiOperation (value = "修改套餐")
    @PutMapping
    public Result updateSetmeal(@RequestBody SetmealDTO setmealDTO){

        service.updateSetmeal(setmealDTO);
        return Result.success();
    }

    /**
     * 套餐分页查询
     * @param setmealPageQueryDTO 条件
     * @return R
     */
    @ApiOperation(value = "套餐分页查询")
    @GetMapping("/page")
    public Result PageQuery(SetmealPageQueryDTO setmealPageQueryDTO){
        log.info("套餐分页查询:{}",setmealPageQueryDTO);
        PageBean pageBean = service.PageQuery(setmealPageQueryDTO);
        return Result.success(pageBean);
    }

    /**
     * 修改套餐状态
     * @param status 状态
     * @param id 当前主键
     * @return R
     */
    @ApiOperation(value = "修改套餐状态")
    @PostMapping("/status/{status}")
    public Result updateStatus(@PathVariable Integer status,Integer id){
        service.updateStatus(status,id);
        return Result.success();
    }

    /**
     * 批量删除套餐
     * @param ids 套餐主键
     * @return R
     */
    @ApiOperation(value = "批量删除套餐")
    @DeleteMapping
    public Result deleteByIds(List<Integer> ids){
        log.info("套餐批量删除:{}",ids);
        service.deleteByIds(ids);
        return Result.success();
    }

    /**
     * 新增套餐
     *
     * @param setmealDTO 条件
     * @return R
     */
    @ApiOperation(value = "新增套餐")
    @PostMapping
    public Result addSetmeal(@RequestBody SetmealDTO setmealDTO ){
        log.info("新增套餐:{}",setmealDTO);
        service.addSetmeal(setmealDTO);
        return Result.success();
    }

    /**
     * 根据id查询
     * @param id 主键
     * @return R
     */
    @ApiOperation(value = "根据id查询套餐")
    @GetMapping("/{id}")
    public Result selectById(@PathVariable Integer id){
        Setmeal setmeal = service.selectById(id);
        return Result.success(setmeal);
    }
}